import request from '@/service/index.js'

export const queryProductList = (option, page, pageSize) => {
  return request.get('/product', {
    params: {
      option,
      page,
      pageSize,
    },
  })
}

export const addNewProduct = (product) => {
  return request.post('/product', product, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

export const deleteProduct = (productId) => {
  return request.delete('/product', {
    params: { id: productId },
  })
}

export const changeProductStatus = (productId, status) => {
  return request.patch(`/product/status/${productId}/${status}`)
}

export const queryProductEcho = (productId) => {
  return request.get('/product/echo', {
    params: { id: productId },
  })
}

export const updateProduct = (product) => {
  return request.put('/product', product, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

export const searchProduct = (productName, status, productCode, categoryId, productType, page, pageSize) => {
  return request.get('/product/search', {
    params: { productName, status, productCode, categoryId, productType, page, pageSize },
  })
}

export const querySimpleProductInfo = (keyword) => {
  if (!keyword) return null
  return request.get('/product/simple/search', {
    params: {
      keyword,
    },
  })
}

export const queryCouponProductInfo = (ids) => {
  return request.get('/product/coupon/product/info', {
    params: {
      productIds: ids,
    },
  })
}

export const queryProductListOptimized = (
  productName,
  brandName,
  productType,
  productId,
  categoryId,
  productStatus,
  currentPage,
  pageSize
) => {
  return request.get('/product/list', {
    params: {
      productId,
      brandName,
      productName,
      productType,
      categoryId,
      productStatus,
      currentPage,
      pageSize,
    },
  })
}
